package com.dsl.tms.controller;

import com.dsl.tms.entity.request.DbSourse;
import com.dsl.tms.service.DataSourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RefreshScope
@RestController
@RequestMapping(path = "/datasource")
@CrossOrigin("${cross_origin.user_client_admin}")
public class DataSourceController {

    @Autowired
    private DataSourceService dataSourceService;

    @RequestMapping(path = "/get_data_source_list",method = RequestMethod.POST)
    public HashMap getDataSourceList(@RequestBody DbSourse keywords){
        return dataSourceService.getDataSourceList(keywords.getToken(),keywords);
    }

    @RequestMapping(path = "/save_datasource",method = RequestMethod.POST)
    public HashMap saveDataSource(@RequestBody DbSourse dbSourse){
        return dataSourceService.saveDataSource(dbSourse.getToken(),dbSourse);
    }

    @RequestMapping(path = "/delete_datasource",method = RequestMethod.GET)
    public HashMap deleteDataSource(@RequestParam("token") String token,@RequestParam("id") int id){
        return dataSourceService.deleteDataSource(token,id);
    }

}
